import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_comm_base_framework/core/utils/ColorsUtil.dart';
import 'package:flutter_comm_base_framework/core/utils/style_util.dart';

/// Widget扩展方法
extension WidgetExtension on Widget {
  addContainer({EdgeInsetsGeometry padding,EdgeInsetsGeometry margin,Color color}){
    return Container(
      padding: padding ?? EdgeInsets.only(left: 10,right: 10),
      margin: margin ?? EdgeInsets.only(left: 10,right: 10),
      color: color,
      child: this,
    );
  }
}

extension TextExtension on Text {}

extension TextFieldExtension on TextField {

     static TextField customer({TextEditingController controller,TextAlign textAlign = TextAlign.left,
      List<TextInputFormatter> inputFormatters,InputDecoration decoration,ValueChanged<String> onChanged,bool obscureText = false,bool enable,hintStyle,suffixIconConstraints,prefixIconConstraints,TextInputType keyboardType,String hintText,Widget rightView,InputBorder enabledBorder,InputBorder disabledBorder, prefixIcon}) {

    return TextField(
        controller: controller,
        keyboardType: keyboardType,
        textAlign: textAlign,
        inputFormatters: inputFormatters,
        enabled: enable,
        onChanged: onChanged,
        obscureText:obscureText,
        toolbarOptions: controller == null ? ToolbarOptions():  ToolbarOptions(copy: controller.text.length>0,),
        decoration: decoration ?? new InputDecoration(
          hintText: hintText,
          hintStyle: hintStyle ?? StyleUtil.textStyle.inptHintTextStyle,
          enabledBorder:  enabledBorder ?? UnderlineInputBorder(
        borderSide: BorderSide(color: ColorsUtil.grey_line)),
          disabledBorder:disabledBorder?? UnderlineInputBorder(
              borderSide: BorderSide(color: ColorsUtil.grey_line)),
          suffixIcon: rightView,
          suffixIconConstraints: suffixIconConstraints,
          prefixIcon: prefixIcon,
          prefixIconConstraints: prefixIconConstraints
        ));
  }

}

class InputDecorationExtension extends InputDecoration{
  // InputDecorationExtension customer({String hintText, TextStyle hintStyle, Image prefixIcon, BoxConstraints prefixIconConstraints});

 // InputDecorationExtension customer({String hintText, TextStyle hintStyle, Image prefixIcon, BoxConstraints prefixIconConstraints});

  static InputDecoration customer({icon,
    labelText,
    labelStyle,
    helperText,
    helperStyle,
    helperMaxLines,
    hintText,
    hintStyle,
    hintMaxLines,
    errorText,
    errorStyle,
    errorMaxLines,
    hasFloatingPlaceholder = true, // ignore: deprecated_member_use_from_same_package
    floatingLabelBehavior = FloatingLabelBehavior.auto,
    isDense,
    contentPadding,
    prefixIcon,
    prefixIconConstraints,
    prefix,
    prefixText,
    prefixStyle,
    suffixIcon,
    suffix,
    suffixText,
    suffixStyle,
    suffixIconConstraints,
    counter,
    counterText,
    counterStyle,
    filled,
    fillColor,
    focusColor,
    hoverColor,
    errorBorder,
    focusedBorder,
    focusedErrorBorder,
    disabledBorder,
    enabledBorder,
    border,
    enabled = true,
    semanticCounterText,
    alignLabelWithHint,
  }) {
    return InputDecoration(labelText: labelText,
        labelStyle: labelStyle,
        helperText: helperText,
        helperStyle: helperStyle,
        helperMaxLines: helperMaxLines,
        hintText: hintText,
        hintStyle: hintStyle ?? StyleUtil.textStyle.inptHintTextStyle,
        hintMaxLines: hintMaxLines,
        errorText: errorText,
        errorStyle: errorStyle,
        errorMaxLines: errorMaxLines,
        hasFloatingPlaceholder: hasFloatingPlaceholder,
        // ignore: deprecated_member_use_from_same_package
        floatingLabelBehavior: floatingLabelBehavior,
        contentPadding: contentPadding,
        prefixIcon: prefixIcon,
        prefixIconConstraints: prefixIconConstraints,
        prefix: prefix,
        prefixText: prefixText,
        prefixStyle: prefixStyle,
        suffixIcon: suffixIcon,
        suffix: suffix,
        suffixText: suffixText,
        suffixStyle: suffixStyle,
        suffixIconConstraints: suffixIconConstraints,
        counter: counter,
        counterText: counterText,
        counterStyle: counterStyle,
        filled: filled,
        fillColor: fillColor,
        focusColor: focusColor,
        hoverColor: hoverColor,
        errorBorder: errorBorder,
        focusedBorder: focusedBorder,
        focusedErrorBorder: focusedErrorBorder,
        enabledBorder:  enabledBorder ?? UnderlineInputBorder(
            borderSide: BorderSide(color: ColorsUtil.grey_line)),
        disabledBorder:disabledBorder?? UnderlineInputBorder(
            borderSide: BorderSide(color: ColorsUtil.grey_line)),
        border: border,
        enabled: enabled,
        semanticCounterText: semanticCounterText,
        alignLabelWithHint: alignLabelWithHint);
  }

}
